package com.lainiao.request;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 *  request 作用域
 *      配合接收数据
 */
@WebServlet("/rsc")
public class request04_RequestScopeCopy extends HttpServlet {
    @Override
    protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        System.out.println("获取域对象内容...");

        // 获取 域对象内容

        // getAttribute的参数name，要与作用域中的数据一致，否则无法匹配
        // getAttribute的返回值是Object，要进行类型转换
        String  name = (String) request.getAttribute("name");
        System.out.println("name：" + name);
        // Alt + Shift + Enter ：自动类型转换（其实是修正代码）
        Integer age = (Integer) request.getAttribute("age");
        System.out.println("age：" + age);
        List<String> list = (List<String>) request.getAttribute("list");
        System.out.println("list：" + list.toString());

        
    }
}
